package com.kw.drug.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kw.drug.entity.Druginfo;
import com.kw.drug.entity.Saleinfo;
import com.kw.drug.mapper.SaleinfoMapper;
import com.kw.drug.service.SaleinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SaleinfoServiceImpl implements SaleinfoService {

    @Autowired
    SaleinfoMapper saleinfoMapper;

    @Override
    public IPage<Saleinfo> selectDruginfoPage(int pageNum, int pageSize, String param) {
        QueryWrapper<Saleinfo> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotEmpty(param)) {
            queryWrapper.like("dname", param);
        }
        Page<Saleinfo> page = new Page<>(pageNum, pageSize);
        return saleinfoMapper.selectPage(page, queryWrapper);
    }

    @Override
    public Saleinfo selectById(int id) {
        Saleinfo saleinfo = saleinfoMapper.selectById(id);
        return saleinfo;
    }

    @Override
    public Integer updateSaleInfo(Saleinfo saleinfo) {

        int update = saleinfoMapper.updateById(saleinfo);
        return update;
    }

    @Override
    public Integer deleteSaleInfoById(Integer id) {
        int i = saleinfoMapper.deleteById(id);
        return i;
    }

    @Override
    public Integer addSaleInfo(Saleinfo saleinfo) {
        int insert = saleinfoMapper.insert(saleinfo);
        return insert;
    }
}
